<!DOCTYPE html>
<html>
<head>
    <title>入院办理--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../layer/layer.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#newNav').click(function(){
                window.location.href="add.html";
            });
        });

        function checkAll(){
            var alls=document.getElementsByName("check");
            var ch=document.getElementById("checks");
            if(ch.checked){
                for(var i=0;i<alls.length;i++){
                    alls[i].checked=true;
                }
            }else{
                for(var i=0;i<alls.length;i++){
                    alls[i].checked=false;
                }
            }
        }
        function delAll(){
            var alls=document.getElementsByName("check");
            var ids= new Array();
            for(let i=0;i<alls.length;i++){
                if(alls[i].checked){
                    ids.push(alls[i].value);
                }
            }
            if(ids.length>0){
                if(confirm("确认操作?")){
                    let windouId = layer.load();
                    $.ajax({
                        type: "GET",
                        url: "/hospital/updateState",
                        data: {ids:ids},
                        traditional: true,
                        dataType: "json",
                        success: function (vo) {
                            layer.close(windouId);
                            layer.msg(vo.msg);
                        }
                    });
                }
            }else{
                alert("请选中要操作的项");
            }
        }
    </script>
</head>
<body>

<form action="#" id="myForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病例号：</td>
        <td><input type="text" name="hosR_id" value=""/></td>
		
        <td width="10%" class="tableleft">主治医生：</td>
        <td><input type="text" name="d_name" value=""/></td>
		
        <td width="10%" class="tableleft">科室：</td>
        <td><input type="text" name="d_keshi" value=""/></td>
    </tr>
    <tr>
		
        <td width="10%" class="tableleft">住院时间：</td>
		
		  <td colspan="5">
			<input type="text" name="beginDate" value=""/>&nbsp;至&nbsp;<input type="text" name="endDate" value=""/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="button" class="btn btn-primary" onclick="load()">查询</button>
            <button type="reset" class="btn btn-primary" >清空</button>
			
        </td>
    </tr>
</table>

   
<table class="table table-bordered table-hover definewidth m10" >
   <thead>
    <tr>
    	<th><input type="checkbox" id="checks" onChange="checkAll();"></th>
        <th>病历号</th>
        <th>姓名</th>
        <th>床位号</th>
        <th>联系电话</th>
        <th>押金</th>
        <th>主治医生</th>
        <th>入院时间</th>
        <th>科室</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="hboby">
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1103</td>
            <td style="vertical-align:middle;">黄飞鸿</td>
            <td style="vertical-align:middle;">4343</td>
            <td style="vertical-align:middle;">13127653423</td>
            <td style="vertical-align:middle;">2000元</td>
            <td style="vertical-align:middle;">程俊</td>
            <td style="vertical-align:middle;">2015-01-05 12:33:56</td>
            <td style="vertical-align:middle;">血液科</td>
            <td style="vertical-align:middle;">已住院</td>
            <td style="vertical-align:middle;">
				<a href="look.html">详情>></a>&nbsp;&nbsp;&nbsp;
				<a href="edit.html">更改</a>&nbsp;&nbsp;&nbsp;
				<a href="add_many.html">缴纳押金</a>&nbsp;&nbsp;&nbsp;
			</td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1103</td>
            <td style="vertical-align:middle;">黄飞鸿</td>
            <td style="vertical-align:middle;">4343</td>
            <td style="vertical-align:middle;">13127653423</td>
            <td style="vertical-align:middle;">2000元</td>
            <td style="vertical-align:middle;">程俊</td>
            <td style="vertical-align:middle;">2015-01-05 12:33:56</td>
            <td style="vertical-align:middle;">血液科</td>
            <td style="vertical-align:middle;">已退院</td>
            <td style="vertical-align:middle;">
				<a href="look.html">详情>></a>&nbsp;&nbsp;&nbsp;
			</td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1103</td>
            <td style="vertical-align:middle;">黄飞鸿</td>
            <td style="vertical-align:middle;">4343</td>
            <td style="vertical-align:middle;">13127653423</td>
            <td style="vertical-align:middle;">2000元</td>
            <td style="vertical-align:middle;">程俊</td>
            <td style="vertical-align:middle;">2015-01-05 12:33:56</td>
            <td style="vertical-align:middle;">血液科</td>
            <td style="vertical-align:middle;">已结算</td>
            <td style="vertical-align:middle;">
				<a href="look.html">详情>></a>&nbsp;&nbsp;&nbsp;				
				<a href="javascript:alert('退院成功！');">退院</a>&nbsp;&nbsp;&nbsp;
				<a href="javascript:alert('出院成功！');">出院</a>
			</td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1103</td>
            <td style="vertical-align:middle;">黄飞鸿</td>
            <td style="vertical-align:middle;">4343</td>
            <td style="vertical-align:middle;">13127653423</td>
            <td style="vertical-align:middle;">2000元</td>
            <td style="vertical-align:middle;">程俊</td>
            <td style="vertical-align:middle;">2015-01-05 12:33:56</td>
            <td style="vertical-align:middle;">血液科</td>
            <td style="vertical-align:middle;">已出院</td>
            <td style="vertical-align:middle;">
				<a href="look.html">详情>></a>&nbsp;&nbsp;&nbsp;

			</td>
        </tr>
    </tbody>
  </table>

    <table class="table table-bordered table-hover definewidth m10" >
        <tr>
            <th colspan="5">
                <div class="form-group">
                    <div id="page" class="inline pull-right page" style="text-align: right">
                        <ul class="pagination" style="margin: 0;">
                            <li name="pageLi" id="firstPage" ><a href="javascript:void(0)">首页</a></li>
                            <li name="pageLi" id="prePage" ><a href="javascript:void(0)">上一页</a></li>
                            <li name="1" id="num1Page"><a href="javascript:void(0)">1</a></li>
                            <li name="2" id="num2Page"><a href="javascript:void(0)">2</a></li>
                            <li name="3" id="num3Page"><a href="javascript:void(0)">3</a></li>
                            <li name="pageLi" id="nextPage"><a href="javascript:void(0)">下一页</a></li>
                            <li name="pageLi" id="lastPage"><a href="javascript:void(0)">末页</a></li>
                            <input type="hidden" class="form-control" name="pageNum" value="1" />
                            &nbsp;&nbsp;&nbsp;共<span class='current' id="total">32</span>条记录
                            <span class='current' id="pageNum"> 1 </span>/<span class='current' id="pages"> 33 </span>页
                        </ul>
                    </div>
                    <div>
                        <button type="button" class="btn btn-success" id="newNav">添加住院信息</button>&nbsp;&nbsp;&nbsp;
                        <button type="button" class="btn btn-success" id="outPro" onClick="delAll();">出院</button>&nbsp;&nbsp;&nbsp;
                        <button type="button" class="btn btn-success" >导出Excel</button>
                    </div>
                </div>
            </th>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    var pi = null;
    $(function (){
        load();
        $("ul[class='pagination']>li").click(function (){
            if (($(this).attr("class")) == 'disabled')
                return;
            let num=$(this).attr("name");
            $("input[name='pageNum']").val(num);
            let windowId = layer.load();
            load();
            layer.close(windowId);
        });
    });

    $("#prePage").click(function(){
        if (pi.isFirstPage){
            layer.msg("已经是第一页了！",function (){});
        }
    });
    $("#nextPage").click(function(){
        if (pi.isLastPage){
            layer.msg("已经是最后一页了！",function (){});
        }
    });

    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }

    function fillPageData(pageInfo) {
        //填充信息
        $("#total").html(pageInfo.total);
        $("#pageNum").html(pageInfo.pageNum);
        $("#pages").html(pageInfo.pages);
        //设置按钮的属性值和样式
        $("#firstPage").attr("name",1);
        $("#prePage").attr("name",pageInfo.prePage);
        $("#nextPage").attr("name",pageInfo.nextPage);
        $("#lastPage").attr("name",pageInfo.pages);
        $("#firstPage").removeClass("disabled");
        $("#prePage").removeClass("disabled");
        $("#nextPage").removeClass("disabled");
        $("#lastPage").removeClass("disabled");
        if (pageInfo.isFirstPage) {//如果是第一页：上一页和首页禁用
            $("#firstPage").addClass("disabled");
            $("#prePage").addClass("disabled");
        }
        if (pageInfo.isLastPage) {//如果已经是最后一页：下一页和末页禁用
            $("#nextPage").addClass("disabled");
            $("#lastPage").addClass("disabled");
        }
    }

    function load(){
        let url = document.location.toString();
        let pageNum = url.GetValue("pageNum");
        if (pageNum != null && $("input[name='pageNum']").val() != null) {
            $("input[name='pageNum']").val(pageNum);
        }
        $.ajax({
            type: "GET",
            url: "/hospital/list",
            data: $("#myForm").serialize(),//主要是分页和多条件参数数据
            dataType:"json",
            success: function(vo){
                //alert( "Data Saved: " + vo );
                if (vo.code == 404){
                    layer.msg(vo.msg);
                }else {
                    pi = vo.pageInfo;
                    let list=vo.pageInfo.list;
                    let str="";
                    for(let i=0;i<list.length;i++){
                        let obj=list[i];
                        let beH_id=obj.beH_id;
                        let hosR_id=obj.hosregister.hosR_id;
                        let hosR_name=obj.hosregister.hosR_name==null?'':obj.hosregister.hosR_name;
                        let beH_patBed=obj.beH_patBed==null?'':obj.beH_patBed;
                        let hosR_phone=obj.hosregister.hosR_phone==null?'':obj.hosregister.hosR_phone;
                        let beH_antecedent=obj.beH_antecedent==null?'':obj.beH_antecedent;
                        let d_name=obj.hosregister.doctor.d_name==null?'':obj.hosregister.doctor.d_name;
                        let beH_inTime=obj.beH_inTime==null?'':obj.beH_inTime;
                        let d_keshi=obj.hosregister.doctor.d_keshi==null?'':obj.hosregister.doctor.d_keshi;
                        let beH_state=obj.beH_state;
                        let state="";
                        let btnStr="";
                        if(beH_state=='0'){
                            state="已住院";
                            btnStr='<a href="javascript:0;" onclick="look(' + beH_id + ')">详情>>></a>&nbsp;'+
                                '<a href="javascript:0;" onclick="edit(' + beH_id + ')">更改</a>';
                        }else{
                            state="已出院";
                            btnStr='<a href="javascript:0;" onclick="look(' + beH_id + ')">详情>>></a>';
                        }
                        str+='<tr>' +
                            '            <td style="vertical-align:middle;"><input type="checkbox" name="check" value="'+beH_id+'"></td>' +
                            '            <td style="vertical-align:middle;">'+hosR_id+'</td>' +
                            '            <td style="vertical-align:middle;">'+hosR_name+'</td>' +
                            '            <td style="vertical-align:middle;">'+beH_patBed+'</td>' +
                            '            <td style="vertical-align:middle;">'+hosR_phone+'</td>' +
                            '            <td style="vertical-align:middle;">'+beH_antecedent+'</td>' +
                            '            <td style="vertical-align:middle;">'+d_name+'</td>' +
                            '            <td style="vertical-align:middle;">'+beH_inTime+'</td>' +
                            '            <td style="vertical-align:middle;">'+d_keshi+'</td>' +
                            '            <td style="vertical-align:middle;">'+state+'</td>' +
                            '            <td style="vertical-align:middle;">'+btnStr+'</td>'+
                            '</tr>'
                    }
                    $("#hboby").html(str);
                    //填充分页数据
                    fillPageData(vo.pageInfo);
                }
            }
        });
    }

    function look(beH_id){
        let pageNum=$("input[name='pageNum']").val();
        window.location.href="/hospital/look.html?beH_id="+beH_id+"&pageNum="+pageNum;
    }

    function edit(beH_id){
        let pageNum=$("input[name='pageNum']").val();
        window.location.href="/hospital/edit.html?beH_id="+beH_id+"&pageNum="+pageNum;
    }
</script>